﻿using NUnit.Framework;
using ScottPlot.PlotStyles;
using SugarProject.Core;

namespace WordStudy20250123.T002;

[TestFixture]
class ChartTest01
{

    [Test]
    public void Test01()
    {
        var xValues = new List<double> { 0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900,
                                         2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3400, 3500, 3600, 3700, 3800, 3900 };
        var yValues = new List<double> { 2, 7, 25, 6.5, 5.5, 4.8, 7.2, 8.9, double.NaN, double.NaN, double.NaN, double.NaN, 5.8, 4.8, 7.2, 6.9, 6.3, 8.9, 9.3, 4.9,
                                        8.2, 4, 8, 6.5, 5.5, 4.8, 7.6, 8.9, 6.3, double.NaN, double.NaN, 6.5, 5.8, 7.8, 7.2, 6.9, 6.0, 8.9, 5.3, 7.9 };
        string xAxisTitle = "时间(s)";
        string yAxisTitle = "有功功率(kW)";
        string outputPath = @"D:\data\WordStudy20250123\ChartTest01\linechart_double.png";

        ChartHelper.GenerateLineChart(xValues, yValues, xAxisTitle, yAxisTitle, outputPath);
        Console.WriteLine("折线图已生成并保存到 " + outputPath);
    }

    [Test]
    public void Test02()
    {
        var xValues = new List<DateTime>();
        var startTime = new DateTime(2025, 1, 1, 0, 0, 0);
        for (int i = 0; i < 40; i++)
        {
            xValues.Add(startTime.AddSeconds(i));
        }
        var yValues = new List<double> { 2, 4, 6, double.NaN, double.NaN, 4.8, 7.2, 8.9, 6.3, 4.9, 6, 6.5, 5.8, 4.8, 7.2, 6.9, 6.3, 8.9, 9.3, 4.9,
                                        8.2, 4, 8, 6.5, 5.5, 4.8, 7.6, 8.9, 6.3, 4.9, 4, 6.5, 5.8, 7.8, 7.2, 6.9, 6.0, double.NaN, double.NaN, double.NaN };
        string xAxisTitle = "时间(s)";
        string yAxisTitle = "有功功率(kW)";
        string outputPath = @"D:\data\WordStudy20250123\ChartTest01\linechart_time.png";

        ChartHelper.GenerateLineChart(xValues, yValues, xAxisTitle, yAxisTitle, outputPath);
        Console.WriteLine("折线图已生成并保存到 " + outputPath);
    }

    [Test]
    public void Test03()
    {
        var xValues = new List<double> { 0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900,
                                         2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3400, 3500, 3600, 3700, 3800, 3900 };
        var yValues1 = new List<double> { 6, 7, 6, 6.9, 5.5, 8.8, 7.2, 8.2, 6.3, 5.9, 9, 6.5, 5.8, 8.8, 7.2, 6.9, 6.3, 8.2, 9.3, 5.9,
                                        6.2, 4, 8, double.NaN, double.NaN, 7.8, 7.6, 8.9, 6.3, 5.9, 4, 6.5, 5.8, 5.8, 7.2, 4.9, 6.0, 8.9, 7.3, 4.9 };
        var yValues2 = new List<double> { 2, 3, 6, 6.5, 4.5, 3.8, 7.2, 5.9, 5.3, 4.9, 6, 6.5, 4.8, 4.8, 4.2, 2.9, 6.3, 3.9, 4.3, 1.9,
                                        4.2, 4, 5, 4.5, 5.5, 2.8, 7.6, 4.1, 6.3, 4.9, 4, 3.5, 5.8, double.NaN, double.NaN, 4.9, 3.0, 5.9, 4.3, 2.9 };
        var yValues3 = new List<double> { 2, 4, 6, 6.5, 5.5, 4.8, 7.2, 8.9, 6.3, 4.9, 6, 6.5, 5.8, 4.8, 7.2, 6.9, double.NaN, double.NaN, 9.3, 4.9,
                                        8.2, 4, 8, 6.5, 5.5, 4.8, 7.6, 8.9, 6.3, 4.9, 4, 6.5, 5.8, 7.8, 7.2, 6.9, 6.0, 8.9, 5.3, 7.9 };
        List<List<double>> yValues = new List<List<double>> { yValues1, yValues2, yValues3 };
        List<string> lineLabels = new List<string> { "Line 1", "Line 2", "Line 3" };

        string xAxisTitle = "时间(s)";
        string yAxisTitle = "有功功率(kW)";
        string outputPath = @"D:\data\WordStudy20250123\ChartTest01\mullinechart_double.png";

        ChartHelper.GenerateMultiLineChart(xValues, yValues, lineLabels, xAxisTitle, yAxisTitle, outputPath);
        Console.WriteLine("折线图已生成并保存到 " + outputPath);
    }

    [Test]
    public void Test04()
    {
        var xValues = new List<DateTime>();
        var startTime = new DateTime(2025, 1, 1, 0, 0, 0);
        for (int i = 0; i < 40; i++)
        {
            xValues.Add(startTime.AddSeconds(i));
        }
        var yValues1 = new List<double> { 2, 4, 6, 6.5, 5.5, 4.8, 7.2, 8.9, 6.3, 4.9, 6, 6.5, 5.8, 4.8, 7.2, 6.9, 6.3, 8.9, 9.3, 4.9,
                                        8.2, 4, 8, 6.5, 5.5, double.NaN, double.NaN, 8.9, 6.3, 4.9, 4, 6.5, 5.8, 7.8, 7.2, 6.9, 6.0, 8.9, 5.3, 7.9 };
        var yValues2 = new List<double> { 6, 4, 6, 6.9, 5.5, 8.8, 7.2, 8.2, 6.3, 4.9, 9, 6.5, 5.8, 8.8, 7.2, 3.9, 6.3, 8.2, 9.3, 5.9,
                                        2.2, 4, 8, 4.5, 5.5, 7.8, 7.6, 8.9, 6.3, 2.9, 4, 6.5, 5.8, 5.8, double.NaN, double.NaN, 6.0, 8.9, 2.3, 4.9 };
        var yValues3 = new List<double> { 2, 5, 6, 6.5, 5.5, 3.8, 7.2, 8.9, 5.3, 4.9, 6, 6.5, 4.8, 4.8, 7.2, 2.9, 6.3, 8.9, 4.3, 1.9,
                                        4.2, double.NaN, double.NaN, 4.5, 5.5, 2.8, 7.6, 8.1, 6.3, 4.9, 4, 3.5, 5.8, 7.8, 7.2, 4.9, 6.0, 5.9, 4.3, 2.9 };
        List<List<double>> yValues = new List<List<double>> { yValues1, yValues2, yValues3 };
        List<string> lineLabels = new List<string> { "Line 1", "Line 2", "Line 3" };

        string xAxisTitle = "时间(s)";
        string yAxisTitle = "有功功率(kW)";
        string outputPath = @"D:\data\WordStudy20250123\ChartTest01\mullinechart_time.png";

        ChartHelper.GenerateMultiLineChart(xValues, yValues, lineLabels, xAxisTitle, yAxisTitle, outputPath);
        Console.WriteLine("折线图已生成并保存到 " + outputPath);
    }


    [Test]
    public void Test05()
    {
        var xValues = new List<double> { 0, 2, 4, 6, 8, 10, 12, 14, 16, 18 };
        var y1Values = new List<double> { 6, 4, 6, 6.9, 5.5, 8.8, 7.2, 8.2, 6.3, 4.9 };
        var y2Values = new List<double> { 12, 15, 16, 16.5, 15.5, 13.8, 17.2, 18.9, 15.3, 14.9 };

        string xAxisTitle = "时间(s)";
        string y1AxisTitle = "有功功率(kW)";
        string y2AxisTitle = "无功功率(kW)";
        string outputPath = @"D:\data\WordStudy20250123\ChartTest01\dualchart_line.png";

        ChartHelper.GenerateDualLineChart(xValues, y1Values, y2Values, xAxisTitle, y1AxisTitle, y2AxisTitle, outputPath);
        Console.WriteLine("双Y轴折线图已生成并保存到 " + outputPath);
    }

    [Test]
    public void Test06()
    {
        var xValues = new List<double> { 0, 2, 4, 6, 8, 10, 12, 14, 16, 18 };
        var y1Values = new List<double> { 6, 4, 6, 6.9, 5.5, 8.8, 7.2, 8.2, 6.3, 4.9 };
        var y2Values1 = new List<double> { 22, 25, 26, 26.5, 25.5, 23.8, 27.2, 28.9, 25.3, 24.9 };
        var y2Values2 = new List<double> { 20, 24, 26, 21, 22, 23.8, 22.2, 21.9, 21.3, 21.4 };

        string xAxisTitle = "时间(s)";
        string y1AxisTitle = "电压(V)";
        string y2AxisTitle = "有功功率/无功功率(kW)";
        string legend1 = "电压";
        string legend2 = "有功功率";
        string legend3 = "无功功率";
        string outputPath = @"D:\data\WordStudy20250123\ChartTest01\DualAxisTripleLine.png";

        ChartHelper.GenerateDualAxisTripleLineChart(
            xValues,
            y1Values,
            y2Values1,
            y2Values2,
            xAxisTitle,
            y1AxisTitle,
            y2AxisTitle,
            legend1,
            legend2,
            legend3,
            outputPath
        );

        Console.WriteLine("双Y轴折线图已生成并保存到 " + outputPath);
    }
}
